import java.util.LinkedList;
import java.util.List;

// author: Dmitriy Zabranskiy 2012(c)
//

public class Adapter {
    // Special class for wrapping incubator and other information
    static final int POPULATION_SIZE = 100;
    static final int LECTURE_COUNT = 30;

    static Incubator incubator;
    private static List<Tutor> tutors = new LinkedList<Tutor>();
    private static Exemplar bestExemplar;
    private static int generationSize;
    
    public static void addTutor(Tutor tutor) {
    	tutors.add(tutor);
    }
    
    public static void delTutor(String name) {
    	for (Tutor tutor : tutors) {
    		if (tutor.getName().equals(name)) {
    			tutors.remove(tutor);
    		}
    	}
    }
    
    public static Tutor getTutor(String name) {
    	for (Tutor tutor : tutors) {
    		if (tutor.getName().equals(name)) {
    			return tutor;
    		}
    	}
    	
    	return null;
    }    
    
    public static void setTutor(Tutor newTutor) {
    	for (Tutor tutor : tutors) {
    		if (tutor.getName().equals(newTutor.getName())) {
    			int idx = tutors.indexOf(tutor);
    			tutors.remove(tutor);
    			tutors.add(idx, newTutor);  
    			return;
    		}
    	}
    }
    
    public static List<Tutor> getTutors() {
    	return tutors;
    }
    
    public static Exemplar getBestExemplar() {
    	return bestExemplar;
    }
    
    public static int getGenerationSize() {
    	return generationSize;
    }
    // Spawn schedule depending on the size of a generation
    public static void genSchedule(int generationSize) throws CloneNotSupportedException {
    	Adapter.generationSize = generationSize;
    	Exemplar.setTutors(tutors);
        incubator = Incubator.getInstance(POPULATION_SIZE, LECTURE_COUNT);
        bestExemplar = incubator.generate(generationSize);
        System.out.println("Schedule:");
        System.out.println(bestExemplar.toString());
        
        Tutor[] newTutors = Exemplar.getTutors();
        for(int i = 0; i < newTutors.length; i++){
        	System.out.println("tutor " + i);
        	System.out.println(newTutors[i].toString());
        }
    }
}
